<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.css" />
    <style type="text/css">
        .aui-list .aui-list-item-media {
            width: 3rem;
        }
        .notes-add {
            position: fixed;
            left: 0.5rem;
            bottom: 0.5rem;
            width: 3rem;
            z-index: 99;
        }
        textarea {
            height: 8rem;
            background-color: #ffffff;
            padding: 0.5rem;
        }
        .photos img {
            display: block;
            width: 100%;
        }
        .add-photos > div {
            width: 100%;
            height:5.15rem;
            line-height: 5.15rem;
        }
        .add-photos > div .aui-iconfont {
            font-size: 2rem;
            color: #ccc;
        }
        .image-item {
            position: relative;
            height: 5.3rem;
            overflow: hidden;
            background-color: #f0f0f0;
        }
        .image-item img {
            display: block;
            margin: 0 auto;
            width: auto;
            height: 100%;
        }
        .image-item .delete-btn {
            position: absolute;
            left: 50%;
            top: 50%;
            width: 28px;
            height: 28px;
            background-color: rgba(0,0,0,0.7);
            margin-left: -14px;
            margin-top: -14px;
            color: #ffffff;
            text-align: center;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <section class="aui-content-padded">
        <textarea id="msg" name="msg" placeholder="在这里输入内容..."></textarea>
    </section>
    <section class="aui-content-padded aui-clearfix">
        <div class="aui-info">
            <div class="aui-info-item aui-padded-r-10" style="width: 13rem">
                <div>
                    <i class="aui-iconfont aui-icon-location"></i>
                    <span id="location" class="aui-ellipsis">北京市海淀区</span>
                    <input id="coodinate" name="coodinate" type="text" style="display:none">
                </div>
            </div>
            <div class="aui-info-item" style="width: 100px;" tapmode  onclick="getLocation();">
                <i class="aui-iconfont aui-icon-refresh aui-text-info aui-margin-r-5"></i>
                <span class="aui-text-info">重新定位</span>
            </div>
        </div>
    </section>
    <section class="aui-content-padded aui-clearfix">
        <div class="aui-btn aui-btn-block aui-btn-info aui-btn-sm" style="background-color:#03a9f4!important" onclick="sendSos();">发送求助信息</div>
    </section>
</body>
<script src="../script/properties.js" charset="utf-8"></script>
<script src="../script/zepto.min.js" charset="utf-8"></script>
<srcipt src="../script/api.js" charset="utf-8"></srcipt>
<script type="text/javascript">
      apiready = function(){
          getLocation();
      }
      function getLocation(){
        var baiduLocation = api.require('baiduLocation');
         var map = api.require('baiduMap');
         baiduLocation.startLocation({
             accuracy: '100m',
             filter: 1,
             autoStop: true
         }, function(ret, err){
             if( ret.status ){
                $.ajax({
                    url : URL+"edit/getAddress",
                    type : "post",
                    dataType : "json",
                    data : {
                      lat:ret.latitude,
                      lon:ret.longitude
                    },
                    success : function(data) {
                      var result = eval("("+data+")");
                      $('#coodinate').val(ret.longitude+","+ret.latitude);
                      $('#location').text(result.addres);
                    }
                });
             }else{
                 alert( JSON.stringify( err ) );
             }
         });
      }
      function sendSos(){
        api.showProgress({
            style: 'default',
            animationType: 'fade',
            title: '努力加载中...',
            text: '先喝杯茶...',
            modal: false
        });

        var user = eval("("+localStorage.getItem('user')+")");
        $.ajax({
          url:URL+"edit/sendSos",
          type:'post',
          dataType:'json',
          data:{
            id:user.id,
            msg:$('#msg').val(),
            coodinate:$('#coodinate').val()
          },
          success:function(data){
            api.hideProgress();
            var result = eval("("+data+")");
            if(result.key){
              alert(result.msg);
            }else {
              alert(result.msg);
            }
          },
          error:function(){
            alert('error');
          }
        })
      }
</script>
</html>
